#include "gwbase/encrypt/enc_rand.h"

#include <unistd.h>
#include <fcntl.h>
#include <sys/stat.h>

namespace dicom {

void EncGenRandom(void* buf, size_t n) {
#ifdef _WIN32
  HCRYPTPROV hCryptProv;

  CryptAcquireContext(&hCryptProv, NULL, NULL, PROV_RSA_FULL,
                      CRYPT_VERIFYCONTEXT);
  CryptGenRandom(hCryptProv, buf, n);
  if (hCryptProv) CryptReleaseContext(hCryptProv, 0);
#else
  int rand_fd;
  rand_fd = open("/dev/urandom", O_RDONLY);
  read(rand_fd, buf, n);
  close(rand_fd);
#endif
}
}
